using System.Data;
using System.Reflection;
using System.Web;

namespace Isis.Model
{
    /// <summary>
    /// ASP.NET's Trace classes are internal/sealed.  This class allows access to them via reflection
    /// </summary>
    public class TraceAdapter
    {
        private const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Static |
                BindingFlags.Public | BindingFlags.NonPublic;

        private static object _profile;
        private static object Profile
        {
            get
            {
                if(_profile == null)
                {
                    _profile = typeof(HttpRuntime)
                .GetProperty("Profile", FLAGS).GetGetMethod(true)
                .Invoke(null, null);
                }
                return _profile;
            }
        }

        /// <summary>Resets the HttpRuntime trace profile.</summary>
        public void Reset()
        {
            // Use it to reset the tracing profile
            MethodInfo reset = Profile.GetType().GetMethod("Reset", FLAGS);
            reset.Invoke(Profile, null);
        }

        public static object[] GetData()
        {
            return Profile.GetType().GetMethod("GetData", FLAGS).Invoke(Profile, null) as object[];
        }
    }
}